<template>
  <div class="reportMistakeInfoAction el-card is-always-shadow el-card__body">
    <avue-crud
      ref="areadySubmitMainCrud"
      :option="option"
      :table-loading="listLoading"
      :data="tableData"
      :page.sync="page"
      :search.sync="searchForm"
      @search-change="handleFilter"
      @selection-change="selectionChange"
      @on-load="search">
      <template slot="menuRight">
        <el-button type="primary" size="mini" @click="exportExcel">导出</el-button>
      </template>

      <template slot="searchMenu" slot-scope="{row,size}">
        <el-button :size="size" @click="()=>{setSearchFiledsEmpty(row);setSearchFiledsEmpty(searchForm)}" icon="el-icon-delete">清空</el-button>
      </template>
      <template slot-scope="scope" slot="menu">
        <el-button type="text" size="small" plain @click.stop="preview(scope.row,3)">预览</el-button>
      </template>
    </avue-crud>
<!--    <report-mistake-info-editor ref="reportMistakeInfoEditor" v-if="isShowReportMistakeInfoEditor"></report-mistake-info-editor>-->
    <preview ref="preview"></preview>
  </div>
</template>


<script>
    import {getForm, postForm} from '@/api/gen/gen'
    import ExportJsonExcel from "js-export-excel";
    import preview from './preview.vue';
    import moment from 'moment';
    import {
      getgetStationCodes,
      getLineCodes, getStationByCode,getLineAndStationByCode, setSearchFiledsEmpty
    } from "../../../../api/subwayRat/commonCheck";
    import {exportDataToExcel} from "../../../../api/subwayRat/exportSelf";
    import {
      areadySubmitMainOptionList,
      getXw_bom_shouJieSuan_areadySubmit
    } from "../../../../api/stationTiecketManager/shouRuJieSuan/bom/areadySubmitMain";
    import {getPreview} from "../../../../api/stationTiecketManager/shouRuJieSuan/bom/waitSubmitMain";
    export default {
      components:{preview
      },
      data() {
            return {
              row : {},
              listLoading: true,
              fileTemp:{},
              searchForm:{},
              tableData:[],
              page: {
                total: 0, // 总页数
                currentPage: 1, // 当前页数
                pageSize: 20, // 每页显示多少条,
                isAsc: false// 是否倒序
              },
              autoWidth: true,
              downloadLoading: false,
              isShowReportMistakeInfoEditor:false,//是否加载编辑页面
              multipleSelectionRows:[],
              multipleSelectionKeys:[],
              lineCodes:[],
              stationCodes:[],
              reportNameIds:[],
              param:{
                lineCode:"",
                stationCode:'',
                reprotTime:"",
                reportNameId:"",
                settleBeginTime:"",
                settleEndTime:""
              },
              option:areadySubmitMainOptionList(),
            }
        },
        created() {
          if(this.$route.query.row){
            this.row = this.$route.query.row;
            debugger
            if(!this.row.submitLineCode && ! this.row.submitStationCode){
              this.row.submitLineCode = this.row.lineCode;
              this.row.submitStationCode = this.row.stationCode;
            }
            this.addContent('添加',0);
          }
        },
        methods: {
          moment,setSearchFiledsEmpty,
          async exportData(){ // 导出
            this.searchForm.pageNo=1;
            this.searchForm.pageSize=1000000000;
            if(this.selectKeys.length>0){
              exportDataToExcel(this.selectKeys,this.option.column,'线网报表差错更改通知');
            }else {
              let res=await getXw_bom_shouJieSuan_areadySubmit(this.searchForm);
              let data = res.data.data;
              exportDataToExcel(data,this.option.column,'线网报表差错更改通知');
            }
          },
          search(){
            Object.assign(this.searchForm,this.$refs.areadySubmitMainCrud.searchForm);
            Object.assign(this.searchForm,this.page);
            this.searchForm.userCode=this.$store.getters.userInfo.userCode;
            this.searchForm.lineCode=this.$store.getters.userInfo.lineCode;
            this.searchForm.stationCode=this.$store.getters.userInfo.stationCode;
            getXw_bom_shouJieSuan_areadySubmit(this.searchForm).then((res)=>{
              this.tableData=res.data.data;
              this.listLoading = false;
              this.page.total=res.data.total;
            });
          },
          preview(row,type){
              this.$nextTick(()=>{
                getPreview(row);
                this.$refs.preview.search(row,type);
              });
          },
          handleSelectionChange(val,a){
            this.multipleSelectionRows=val;
            this.multipleSelectionKeys=[];
            for(let i=0;i<this.multipleSelectionRows.length;i++){
              this.multipleSelectionKeys.push(this.multipleSelectionRows[i].id);
            }
          },
          initLine(){
            getLineCodes().then(res=>{ //获取线路
              this.lineCodes=res;
            });
          },
          initReportNameIds(){
            // getReports({}).then((res)=>{
            //   this.reportNameIds=res.data.data;
            // })
          },
          changeLine(v){
            getgetStationCodes(v).then(res=>{
              this.stationCodes=res;
            })
          },
          async noticeReport(){

            if(this.multipleSelectionKeys.length<=0){
              this.$message({
                message: '您至少选择一条或多条信息发送通知！',
                type: 'warning'
              });
              return;
            }
            let messageLSList = [];
            for(let i=0;i<this.selectKeys.length;i++){
              let data = await getLineAndStationByCode({"lineCode":this.selectKeys[i].lineCode, "code":this.selectKeys[i].stationCode});
              messageLSList.push({
                "content":"车站：" + data.data[0].name,
                "lineCode":this.selectKeys[i].lineCode,
                "stationCode":this.selectKeys[i].stationCode
              })
            }
            let p = {
              messageLSList:JSON.stringify(messageLSList),
              title:this.$store.getters.tag.label,
              msgType:"通知",
              type:"reportMistakeInfo_001",
              ids:this.multipleSelectionKeys,
              noticeStatus:1
            };
            this.$confirm('您是否要通知此数据？', '提示', {
              confirmButtonText: '是',
              cancelButtonText: '否',
              type: 'warning'
            }).then(() => {
              noticeReport(p).then((res)=>{
                this.$message({
                  message: res.data.code==0?'操作成功':'操作失败',
                  type: res.data.code==0?'success':'error',
                });
                this.search();
              });
            }).catch(() => {
            });
          },
          async exportExcel(){ // 导出
            let p={};
            Object.assign(p,this.searchForm);
            p.pageNo=1;
            p.pageSize=1000000000;
            if(this.multipleSelectionRows.length>0){
              exportDataToExcel(this.multipleSelectionRows,this.option.column,'收入结算BOM已提交');
            }else {
              let res=await get_xw_ReportErrorList(p);
              let data = res.data.data;
              exportDataToExcel(data,this.option.column,'收入结算BOM已提交');
            }
          },
          selectionChange(list){
            this.multipleSelectionRows=list;
            this.multipleSelectionKeys=[];
            for(let i=0;i<list.length;i++){
              this.multipleSelectionKeys.push(list[i].id);
            }
          },
          handleFilter(params, done) {
            Object.assign(this.searchForm,params);
            this.search()
            done()
          },
        },
      mounted() {
        this.search();
        this.initLine();
        this.initReportNameIds();
      }
    }
</script>
<style lang="scss">

</style>
